home *** CD-ROM | disk | FTP | other *** search
- Path: mudskipper.cac.psu.edu!user
- From: fcusack@tdx.org (frank.)
- Newsgroups: comp.lang.c
- Subject: Re: simple code, argc, argv, strcmp()
- Date: Wed, 07 Feb 1996 20:17:16 -0400
- Organization: Penn State University, Center for Academic Computing
- Message-ID: <fcusack-0702962017160001@mudskipper.cac.psu.edu>
- References: <11f7cc$17261a.3b3@daprez> <4etj7c$bma@news.iag.net> <fcusack-0202961621470001@mudskipper.cac.psu.edu> <31177C77.167EB0E7@texas.net> <fcusack-0702961519200001@mudskipper.cac.psu.edu>
- NNTP-Posting-Host: mudskipper.cac.psu.edu
-
- In article <fcusack-0702961519200001@mudskipper.cac.psu.edu>,
- fcusack@tdx.org (frank.) wrote:
-
- > In article <31177C77.167EB0E7@texas.net>, Michael Douglass
- > <mikedoug@texas.net> wrote:
- >
- > > > > >int main (int argc, char **argv) {
- > > > > >
- > > > > > void Usage (void);
- > > > > > void Encode (int, char **);
- > > > > > void Decode (int, char **);
- > > > > >
- > > > > > if (!strcmp(argv[1],"-d") || !strcmp(argv[1],"-e")) {
- > > > > > Usage();
- > > > > > }
- > > > > <snip>
- > >
- > > > argv[1] is always guaranteed to exist. It is simply NULL if there were no
- > > > arguments.
- > >
- > > Even if this is so... You still do *not* want to call strcmp with a NULL
- > pointer
- > > now do we? Does that not make your argument moot, and make the
- previous point
- > > that you should always check argc to make sure that you *have* at least
- > one argument
- > > a very good argument?
- >
- > well, a) argv[1] is not guaranteed to exist. Sorry for that mistake.
- >
- > b) I meant that if argv[0] is passed (and is the command name), then
- > argv[1] is a pointer to a null string, not a null pointer.
-
- ARG! (pun intended :) )
-
- of course, the above is wrong. argv[argc] is guaranteed to be NULL.
- ~Frank
- -- I am Pentium of Borg. Division is futile. You will be approximated. --
- -- If you build it, they will come --> http://www.tdx.org/~fcusack/ --
- -- PGP key fingerprint: 01 C0 C0 B9 CC 78 67 0F 3F 64 80 65 8B 0F F9 EA --
-